-
Notifications
You must be signed in to change notification settings - Fork 518
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to create levels (was: Introduce a createLevel call, document, add tests) #465
base: master
Are you sure you want to change the base?
Conversation
the default set. It's imperfect in re: dtrace support, but it's also self-contained and easy to understand. Caveats: - There's no way to dynamically add dtrace probes after-the-fact of logger creation, so there's no way to trace levels in loggers that were instantiated prior to the level creation - I think this is completely safe in-re: Logger fields; we may be adding functions to the prototype left-and-right, but they'll be shadowed by the actual Logger instance, and we won't overwrite anything that exists - I'm a little uncomfortable with all the hand-holding / don't-shoot-yourself-in-the-foot going on in the createLogger call, but it's certainly safer - The documentation could be better
This actually very nicely solves a problem I currently have - I have events that are infrequent, but important, and I want to surface them above the regular "info" logging I do to allow for postmortem debugging. I could prepend each message with a custom identifier, but a separate "notice" loglevel is a much more efficient way of going about it. |
👍 in this. It would be really good for us to be able to configure Bunyan to match the Google Stackdriver levels. https://cloud.google.com/logging/docs/api/reference/rest/v2/LogEntry#LogSeverity |
It would be great if this were integrated into Bunyan. We have the need for a |
👍 Would love this for something like |
@trentm can this get looked at? Great add 👍 |
I am also running into a need for this with |
This would be very useful. |
this would be super useful, end update on this? |
This would be very very useful. In the meantime, here's our workaround. Warning: h4x incoming. So if you pass an object to the log methods it is possible to override the defaults for the final log output. You can override the logger.fatal({ level: 35, foo: 'bar' }, 'My message')
// outputs { ... "level":35,"baz":"bing","msg":"foo bar" ... } Next step: monkey patch. const logger = require('bunyan').createLogger({ name: 'myLogger', level: 34 })
logger.notice = (msg, ...args) => {
if (typeof msg === 'string') {
logger.fatal({ level: 35 }, msg, ...args)
}
else if (typeof msg === 'object') {
logger.fatal({ level: 35, ...msg }, ...args)
}
else {
throw new Error('Invalid arguments provided')
}
} |
This is a -- possibly stopgap -- solution to the need for levels beyond
the default set. It's imperfect in re: dtrace support, but it's also
self-contained and easy to understand.
Caveats:
of logger creation, so there's no way to trace levels in loggers
that were instantiated prior to the level creation
adding functions to the prototype left-and-right, but they'll be
shadowed by the actual Logger instance, and we won't overwrite
anything that exists
don't-shoot-yourself-in-the-foot going on in the createLogger
call, but it's certainly safer